<?php
/**
 * cms后台文章修改管理页
 * author wang
 * mail:970633164@qq.com
 */

define("PHP_IN",true);
require "../include/init.php";
require "checklogin.php";
require ROOT_PATH."cms/smart_connection.php";

$page = isset($_GET['page']) ? $_GET['page'] : 1;
$articleid = isset($_GET['articleid'])? $_GET['articleid']:0;

if(isset($_POST['dosubmit'])){

    $title = $_POST['title'];
    $isdisplay = intval($_POST['isdisplay']);
    $content = isset($_POST['editorValue']) ? $_POST['editorValue'] : "";
    if($title=="" || $content==""){
        alert("请填写完整的文章内容");
        exit;
    }
    $articleid = $_POST['articleid'];
    $sql = "UPDATE article SET title='$title',content='$content',isdisplay='$isdisplay' WHERE articleid = '$articleid'";
    $result = $db->query($sql);
    if ($result) {
        alert("修改成功", "article_list.php?page=".$page);
    } else {
        alert("修改失败");
    }
}

if(isset($_GET['articleid'])){
    $sql = "SELECT * FROM article WHERE articleid = $articleid";
    $result = $db->query($sql);
    if($result && $db->num_rows($result)){
        $article = $db->fetch_one($result);
    }else{
        alert("该文章不存在！","article_list.php");
    }
}else{
    alert("文章不存在！","article_list.php");
}

$smarty->assign("page",$page);
$smarty->assign("article",$article);

$smarty->display("article_edit.tpl");
$db->close();

?>
